export let source = [] as any[]
export const getTabelTree = (res: any, sourceData?: any) => {
    if (res === 0)
        res = {
            title: '根',
            id: '0',
            type: 0,
            url: '根节点',
            desc: '无法操作',
            sort: 0,
            icon: 'home',
            permission: 'root'
        }
    if (sourceData) source = sourceData
    res.children = findChildrens(res.id)
    if (res.children.length > 0) {
        res.children.forEach((item: any) => {
            getTabelTree(item)
        })
        res.children.sort((b: any, a: any) => b['sort'] - a['sort'])
    }
    return res
}

const findChildrens = (parentId: string) => {
    let parent = source.filter((el) => el.parentId === parentId)
    return JSONUtil.cp(parent)
}
